package main


import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
)
func check(i,j int,v [][]int)bool{
	val,len:=v[i][0]+v[j][0],len(v[i])
	for x:=1;x<len;x++{
		if val!=v[i][x]+v[j][x]{
			return false
		}
	}
	return true;
}
func main(){
	n,k:=0,0
	//fmt.Scanf("%d %d\n",&n,&k)
	reader:=bufio.NewReader(os.Stdin)
	r,_:=reader.ReadString('\n')
	r=strings.Trim(r,"\n")
	r1:=strings.Split(r," ")
	n,_=strconv.Atoi(r1[0])
	k,_=strconv.Atoi(r1[1])
	//fmt.Printf("%v %v\n",r1,k)
	v:=make([][]int,n)
	mp:=make([][]int,2005)
	cnt:=0
	for i:=0;i<n;i++{
		v[i]=make([]int,k)
		r,_=reader.ReadString('\n')
		r=strings.Trim(r,"\n")
		r1=strings.Split(r," ")
		for j:=0;j<k;j++{
			v[i][j],_=strconv.Atoi(r1[j])
			// fmt.Scanf("%d",&v[i][j])
		}
		d:=v[i][k-1]-v[i][0]
		
		for l:=0;l<len(mp[1000-d]);l++{
			if check(i,mp[1000-d][l],v){ //判断
				cnt++
			}
		}

		mp[1000+d]=append(mp[1000+d],i)
	}
	
	fmt.Printf("%d\n",cnt)




}